# Load libraries ----
library(tidyverse)
library(ggthemes)
library(multcomp)
library(gtsummary)
library(effects)
library(ggeffects)
library(gridExtra)
library(cowplot)
library(grid)
library(haven)
library(srvyr)
library(Hmisc)
library(rio)
library(modelsummary)
library(jtools)
library(xtable)
library(ggpubr)
library(rstatix)
library(interactions)
library(stevemisc)
library(lmtest)
library(sandwich)
library(estimatr)
library(dplyr)
library(kableExtra)
library(flextable)
library(gt)
options(scipen = 999) # Turn off scientific notation

# Define themes ----
mytheme <- function(...){
  theme_clean() +   
    theme(plot.title.position="panel",
          text=element_text(family="serif", color="gray15"), 
          axis.title=element_text(size=12, color="gray15"), 
          axis.text=element_text(size=12, color="gray15"),
          plot.title = element_text(size=12, color = "gray15"), 
          plot.caption=element_text(size = 12),  
          legend.position = "bottom",
          plot.background = element_rect(color="white"), 
          axis.title.y = element_text(margin = margin(t=0,r=10,b=0,l=0)), 
          legend.background = element_rect(color=NA), 
          axis.ticks = element_line(color="gray15"), 
          axis.line.x = element_line(color="gray15"), 
          axis.line.y = element_line(color="gray15"),
          panel.grid.major.y = element_line(color = "grey90", linetype = "solid"),
          legend.text = element_text(size = 16),
          strip.text.x = element_text(size = 18),
          axis.title.x = element_blank())
  }

mytheme2 <- function(...){
  theme_clean() +   
    theme(plot.title.position="panel",
          text=element_text(family="serif", color="gray15"), 
          axis.title=element_text(size=18, color="gray15"), 
          axis.text=element_text(size=12, color="gray15"),
          plot.title = element_text(size=18, color = "gray15"), 
          plot.caption=element_text(size = 12),  
          legend.position = "bottom",
          plot.background = element_rect(color="white"), 
          axis.title.y = element_text(margin = margin(t=0,r=10,b=0,l=0)), 
          legend.background = element_rect(color=NA), 
          axis.ticks = element_line(color="gray15"), 
          axis.line.x = element_line(color="gray15"), 
          axis.line.y = element_line(color="gray15"),
          panel.grid.major.y = element_line(color = "grey90", linetype = "solid"),
          strip.text.x = element_text(size = 18),
          legend.text = element_text(size = 16))
  }

mytheme3 <- function(...){
  theme_clean() +   
    theme(plot.title.position="panel",
          text=element_text(family="serif", color="gray15"), 
          axis.title=element_text(size=12, color="gray15"), 
          axis.text.y=element_text(size=12, color="gray15"),
          axis.text.x = element_text(size=12, color="gray15"),
          plot.title = element_text(size=12, color = "gray15"), 
          plot.caption=element_text(size = 10),  
          plot.background = element_rect(color="white"), 
          axis.title.x = element_text(margin = margin(t=0,r=10,b=0,l=0)), 
          axis.ticks = element_line(color="gray15"), 
          axis.line.x = element_line(color="gray15"), 
          axis.line.y = element_line(color="gray15"),
          panel.grid.major.x = element_line(color = "grey90", linetype = "solid"),
          panel.grid.major.y = element_line(color = "white", linetype = "solid"),
          #legend.position = "bottom",
          legend.text = element_text(size = 12),
          legend.title= element_blank(),
          legend.background = element_rect(color=NA),
          legend.margin=margin(0,0,0,0),
          legend.box.margin=margin(-10,-10,0,-10),
          strip.text.x = element_text(size = 10),
          axis.title.y = element_blank())
  }

mytheme4 <- function(...){
  theme_clean() +   
    theme(plot.title.position="panel",
          text=element_text(family="serif", color="gray15"), 
          axis.title=element_text(size=18, color="gray15"), 
          axis.text=element_text(size=16, color="gray15"),
          plot.title = element_text(size=18, color = "gray15"), 
          plot.caption=element_text(size = 12),  
          legend.position = "bottom",
          plot.background = element_rect(color="white"), 
          axis.title.y = element_text(margin = margin(t=0,r=10,b=0,l=0)), 
          legend.background = element_rect(color=NA), 
          axis.ticks = element_line(color="gray15"), 
          axis.line.x = element_line(color="gray15"), 
          axis.line.y = element_line(color="gray15"),
          panel.grid.major.y = element_line(color = "grey90", linetype = "solid"),
          strip.text.x = element_text(size = 18),
          legend.text = element_text(size = 16))
  }


# Load in data ----
dso = import("Exp.1.data.csv")

ds = dso %>% 
  filter(consent == "I agree to participate", 
         attention =="Slightly interested",
         Finished == "TRUE",
         rid != '') %>% 
  mutate(project_assignment = case_when(PPExperiment_DO=="transportation|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "transportation",
                                        PPExperiment_DO=="public_lands|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "public_lands",
                                        PPExperiment_DO=="employment|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "employment",
                                        PPExperiment_DO=="defense|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "defense",
                                        PPExperiment_DO=="public_safety|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "public_safety",
                                        PPExperiment_DO=="local_economy|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "local_economy",
                                        PPExperiment_DO=="healthcare|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "healthcare",
                                        PPExperiment_DO=="education|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "education",
                                        PPExperiment_DO=="environment|post_feeling|post_effective|post_represent|post_responsible|post_approval" ~ "environment"),
         education_rank = issue_ranking_6,
         employment_rank = issue_ranking_7,
         defense_rank = issue_ranking_10,
         healthcare_rank = issue_ranking_9,
         public_safety_rank = issue_ranking_4,
         public_lands_rank = issue_ranking_3,
         evironment_rank = issue_ranking_5,
         economy_rank = issue_ranking_11,
         transportation_rank = issue_ranking_2,
         education_therm = case_when(education_rank==1 ~ spending_therm_1,
                                     education_rank==2 ~ spending_therm_2,
                                     education_rank==3 ~ spending_therm_3,
                                     education_rank==4 ~ spending_therm_4,
                                     education_rank==5 ~ spending_therm_5,
                                     education_rank==6 ~ spending_therm_6,
                                     education_rank==7 ~ spending_therm_7,
                                     education_rank==8 ~ spending_therm_8,
                                     education_rank==9 ~ spending_therm_9),
         employment_therm = case_when(employment_rank==1 ~ spending_therm_1,
                                      employment_rank==2 ~ spending_therm_2,
                                      employment_rank==3 ~ spending_therm_3,
                                      employment_rank==4 ~ spending_therm_4,
                                      employment_rank==5 ~ spending_therm_5,
                                      employment_rank==6 ~ spending_therm_6,
                                      employment_rank==7 ~ spending_therm_7,
                                      employment_rank==8 ~ spending_therm_8,
                                      employment_rank==9 ~ spending_therm_9),
         defense_therm = case_when(defense_rank==1 ~ spending_therm_1,
                                   defense_rank==2 ~ spending_therm_2,
                                   defense_rank==3 ~ spending_therm_3,
                                   defense_rank==4 ~ spending_therm_4,
                                   defense_rank==5 ~ spending_therm_5,
                                   defense_rank==6 ~ spending_therm_6,
                                   defense_rank==7 ~ spending_therm_7,
                                   defense_rank==8 ~ spending_therm_8,
                                   defense_rank==9 ~ spending_therm_9),
         healthcare_therm = case_when(healthcare_rank==1 ~ spending_therm_1,
                                      healthcare_rank==2 ~ spending_therm_2,
                                      healthcare_rank==3 ~ spending_therm_3,
                                      healthcare_rank==4 ~ spending_therm_4,
                                      healthcare_rank==5 ~ spending_therm_5,
                                      healthcare_rank==6 ~ spending_therm_6,
                                      healthcare_rank==7 ~ spending_therm_7,
                                      healthcare_rank==8 ~ spending_therm_8,
                                      healthcare_rank==9 ~ spending_therm_9),
         public_safety_therm = case_when(public_safety_rank==1 ~ spending_therm_1,
                                         public_safety_rank==2 ~ spending_therm_2,
                                         public_safety_rank==3 ~ spending_therm_3,
                                         public_safety_rank==4 ~ spending_therm_4,
                                         public_safety_rank==5 ~ spending_therm_5,
                                         public_safety_rank==6 ~ spending_therm_6,
                                         public_safety_rank==7 ~ spending_therm_7,
                                         public_safety_rank==8 ~ spending_therm_8,
                                         public_safety_rank==9 ~ spending_therm_9),
         public_lands_therm = case_when(public_lands_rank==1 ~ spending_therm_1,
                                        public_lands_rank==2 ~ spending_therm_2,
                                        public_lands_rank==3 ~ spending_therm_3,
                                        public_lands_rank==4 ~ spending_therm_4,
                                        public_lands_rank==5 ~ spending_therm_5,
                                        public_lands_rank==6 ~ spending_therm_6,
                                        public_lands_rank==7 ~ spending_therm_7,
                                        public_lands_rank==8 ~ spending_therm_8,
                                        public_lands_rank==9 ~ spending_therm_9),
         evironment_therm = case_when(evironment_rank==1 ~ spending_therm_1,
                                      evironment_rank==2 ~ spending_therm_2,
                                      evironment_rank==3 ~ spending_therm_3,
                                      evironment_rank==4 ~ spending_therm_4,
                                      evironment_rank==5 ~ spending_therm_5,
                                      evironment_rank==6 ~ spending_therm_6,
                                      evironment_rank==7 ~ spending_therm_7,
                                      evironment_rank==8 ~ spending_therm_8,
                                      evironment_rank==9 ~ spending_therm_9),
         economy_therm = case_when(economy_rank==1 ~ spending_therm_1,
                                   economy_rank==2 ~ spending_therm_2,
                                   economy_rank==3 ~ spending_therm_3,
                                   economy_rank==4 ~ spending_therm_4,
                                   economy_rank==5 ~ spending_therm_5,
                                   economy_rank==6 ~ spending_therm_6,
                                   economy_rank==7 ~ spending_therm_7,
                                   economy_rank==8 ~ spending_therm_8,
                                   economy_rank==9 ~ spending_therm_9),
         transportation_therm = case_when(transportation_rank==1 ~ spending_therm_1,
                                          transportation_rank==2 ~ spending_therm_2,
                                          transportation_rank==3 ~ spending_therm_3,
                                          transportation_rank==4 ~ spending_therm_4,
                                          transportation_rank==5 ~ spending_therm_5,
                                          transportation_rank==6 ~ spending_therm_6,
                                          transportation_rank==7 ~ spending_therm_7,
                                          transportation_rank==8 ~ spending_therm_8,
                                          transportation_rank==9 ~ spending_therm_9),
         education_allocate = case_when(education_rank==1 ~ Allocation_2,
                                        education_rank==2 ~ Allocation_3,
                                        education_rank==3 ~ Allocation_4,
                                        education_rank==4 ~ Allocation_5,
                                        education_rank==5 ~ Allocation_6,
                                        education_rank==6 ~ Allocation_7,
                                        education_rank==7 ~ Allocation_8,
                                        education_rank==8 ~ Allocation_9,
                                        education_rank==9 ~ Allocation_10),
         employment_allocate = case_when(employment_rank==1 ~ Allocation_2,
                                         employment_rank==2 ~ Allocation_3,
                                         employment_rank==3 ~ Allocation_4,
                                         employment_rank==4 ~ Allocation_5,
                                         employment_rank==5 ~ Allocation_6,
                                         employment_rank==6 ~ Allocation_7,
                                         employment_rank==7 ~ Allocation_8,
                                         employment_rank==8 ~ Allocation_9,
                                         employment_rank==9 ~ Allocation_10),
         defense_allocate = case_when(defense_rank==1 ~ Allocation_2,
                                      defense_rank==2 ~ Allocation_3,
                                      defense_rank==3 ~ Allocation_4,
                                      defense_rank==4 ~ Allocation_5,
                                      defense_rank==5 ~ Allocation_6,
                                      defense_rank==6 ~ Allocation_7,
                                      defense_rank==7 ~ Allocation_8,
                                      defense_rank==8 ~ Allocation_9,
                                      defense_rank==9 ~ Allocation_10),
         healthcare_allocate = case_when(healthcare_rank==1 ~ Allocation_2,
                                         healthcare_rank==2 ~ Allocation_3,
                                         healthcare_rank==3 ~ Allocation_4,
                                         healthcare_rank==4 ~ Allocation_5,
                                         healthcare_rank==5 ~ Allocation_6,
                                         healthcare_rank==6 ~ Allocation_7,
                                         healthcare_rank==7 ~ Allocation_8,
                                         healthcare_rank==8 ~ Allocation_9,
                                         healthcare_rank==9 ~ Allocation_10),
         public_safety_allocate = case_when(public_safety_rank==1 ~ Allocation_2,
                                            public_safety_rank==2 ~ Allocation_3,
                                            public_safety_rank==3 ~ Allocation_4,
                                            public_safety_rank==4 ~ Allocation_5,
                                            public_safety_rank==5 ~ Allocation_6,
                                            public_safety_rank==6 ~ Allocation_7,
                                            public_safety_rank==7 ~ Allocation_8,
                                            public_safety_rank==8 ~ Allocation_9,
                                            public_safety_rank==9 ~ Allocation_10),
         public_lands_allocate = case_when(public_lands_rank==1 ~ Allocation_2,
                                           public_lands_rank==2 ~ Allocation_3,
                                           public_lands_rank==3 ~ Allocation_4,
                                           public_lands_rank==4 ~ Allocation_5,
                                           public_lands_rank==5 ~ Allocation_6,
                                           public_lands_rank==6 ~ Allocation_7,
                                           public_lands_rank==7 ~ Allocation_8,
                                           public_lands_rank==8 ~ Allocation_9,
                                           public_lands_rank==9 ~ Allocation_10),
         evironment_allocate = case_when(evironment_rank==1 ~ Allocation_2,
                                         evironment_rank==2 ~ Allocation_3,
                                         evironment_rank==3 ~ Allocation_4,
                                         evironment_rank==4 ~ Allocation_5,
                                         evironment_rank==5 ~ Allocation_6,
                                         evironment_rank==6 ~ Allocation_7,
                                         evironment_rank==7 ~ Allocation_8,
                                         evironment_rank==8 ~ Allocation_9,
                                         evironment_rank==9 ~ Allocation_10),
         economy_allocate = case_when(economy_rank==1 ~ Allocation_2,
                                      economy_rank==2 ~ Allocation_3,
                                      economy_rank==3 ~ Allocation_4,
                                      economy_rank==4 ~ Allocation_5,
                                      economy_rank==5 ~ Allocation_6,
                                      economy_rank==6 ~ Allocation_7,
                                      economy_rank==7 ~ Allocation_8,
                                      economy_rank==8 ~ Allocation_9,
                                      economy_rank==9 ~ Allocation_10),
         transportation_allocate = case_when(transportation_rank==1 ~ Allocation_2,
                                             transportation_rank==2 ~ Allocation_3,
                                             transportation_rank==3 ~ Allocation_4,
                                             transportation_rank==4 ~ Allocation_5,
                                             transportation_rank==5 ~ Allocation_6,
                                             transportation_rank==6 ~ Allocation_7,
                                             transportation_rank==7 ~ Allocation_8,
                                             transportation_rank==8 ~ Allocation_9,
                                             transportation_rank==9 ~ Allocation_10),
         project_rank = case_when(project_assignment=="transportation" ~ transportation_rank,
                                  project_assignment=="public_lands" ~ public_lands_rank,
                                  project_assignment=="employment" ~ employment_rank,
                                  project_assignment=="defense" ~ defense_rank,
                                  project_assignment=="public_safety" ~ public_safety_rank,
                                  project_assignment=="local_economy" ~ economy_rank,
                                  project_assignment=="healthcare" ~ healthcare_rank,
                                  project_assignment=="education" ~ education_rank,
                                  project_assignment=="environment" ~ evironment_rank),
         project_therm = case_when(project_assignment=="transportation" ~ transportation_therm,
                                   project_assignment=="public_lands" ~ public_lands_therm,
                                   project_assignment=="employment" ~ employment_therm,
                                   project_assignment=="defense" ~ defense_therm,
                                   project_assignment=="public_safety" ~ public_safety_therm,
                                   project_assignment=="local_economy" ~ economy_therm,
                                   project_assignment=="healthcare" ~ healthcare_therm,
                                   project_assignment=="education" ~ education_therm,
                                   project_assignment=="environment" ~ evironment_therm),
         project_allocate= case_when(project_assignment=="transportation" ~ transportation_allocate,
                                     project_assignment=="public_lands" ~ public_lands_allocate,
                                     project_assignment=="employment" ~ employment_allocate,
                                     project_assignment=="defense" ~ defense_allocate,
                                     project_assignment=="public_safety" ~ public_safety_allocate,
                                     project_assignment=="local_economy" ~ economy_allocate,
                                     project_assignment=="healthcare" ~ healthcare_allocate,
                                     project_assignment=="education" ~ education_allocate,
                                     project_assignment=="environment" ~ evironment_allocate),
         project_rank_cat = case_when(project_rank==1 | project_rank==2 | project_rank==3 ~ "high",
                                      project_rank==4 | project_rank==5 | project_rank==6 ~ "mid",
                                      project_rank==7 | project_rank==8 | project_rank==9 ~ "low"),
         project_rank_cat = factor(project_rank_cat, levels=c("low", "mid", "high")),
         project_rank_rev = revcode(project_rank),
         pre_feeling = feeling_grid_2,
         pre_effective = effective_grid_2,
         pre_represent = representation_grid_2,
         pre_responsible = responsible_grid_2,
         pre_feeling_other = feeling_grid_6,
         pre_effective_other = effective_grid_6,
         pre_represent_other = representation_grid_6,
         pre_responsible_other = responsible_grid_6,
         feeling_change =  post_feeling_34 - pre_feeling,
         effective_change =  post_effective_34 - pre_effective,
         represent_change =  post_represent_34 - pre_represent,
         responsible_change =  post_responsible_34 - pre_responsible,
         partyr = case_when(party=="Not very strong Democrat" | party=="Strong Democrat" ~ "dem",
                            party=="Not very strong Republican" | party=="Strong Republican" ~ "rep",
                            party=="Independent" & independent=="More similar to Democrats than Republicans" ~ "ind",
                            party=="Independent" & independent=="More similar to Republicans than Democrats" ~ "ind"), 
         partytwo = case_when(party=="Not very strong Democrat" | party=="Strong Democrat" ~ "dem",
                              party=="Not very strong Republican" | party=="Strong Republican" ~ "rep",
                              party=="Independent" & independent=="More similar to Democrats than Republicans" ~ "dem",
                              party=="Independent" & independent=="More similar to Republicans than Democrats" ~ "rep"),
         income = case_when(income=="Under $10,000" ~ 1, 
                            income=="$10,000-$19,999"~2,
                            income=="$20,000-$29,999" ~ 3,
                            income=="$40,000-$49,999"~4,
                            income=="$50,000-$59,999"~5,
                            income=="$30,000-$39,999" ~ 6,
                            income=="$60,000-$74,999"~7,
                            income=="$75,000-$89,999" ~ 8,
                            income=="$90,000-$119,999"~9,
                            income=="$120,000-$159,999"~10,
                            income=="$160,000-$200,000"~11,
                            income=="Over $200,000"~12),
         resp_gender = case_when(gender== 1  ~ "man",
                                 gender== 2  ~ "woman"),
         age = as.numeric(age), 
         education = case_when(education==1|education==2|education==3|education==4|education==5 ~ "Less_than_Bachelors", 
                               education==6|education==7|education==8 ~ "Bachelors_or_higher"),
         ideo = case_when(ideology=="Very Conservative" ~ 1, 
                          ideology=="Conservative" ~ 2, 
                          ideology=="Slightly Conservative" ~ 3, 
                          ideology=="Moderate" ~ 4, 
                          ideology=="Slightly Liberal" ~ 5, 
                          ideology=="Liberal" ~ 6, 
                          ideology=="Very Liberal" ~ 7),
         black = ifelse(grepl("Black or African American", race), 1, 0), 
         hisplat = ifelse(grepl("Hispanic or Latino", race), 1, 0),
         asam = ifelse(grepl("Asian or Pacific Islander", race), 1, 0),
         natam = ifelse(grepl("American Indian or Alaska Native", race), 1, 0),
         white = ifelse(grepl("White", race), 1, 0),
         multiracial = ifelse(grepl("Multi-racial", race), 1, 0),
         rother = ifelse(grepl("Other", race), 1, 0),
         race = case_when(race=="White" ~ "White",
                          race=="Asian or Pacific Islander" ~ "Asian American",
                          race=="Black or African American" ~ "Black",
                          race=="Hispanic or Latino" ~ "Latino",
                          grepl("Multi-racial", race) ~ "Multi-racial",
                          race=="American Indian or Alaska Native" ~ "Other",
                          race=="Other" ~ "Other",
                          grepl(",", race) ~ "Other"),
         hispanic = case_when(hispanic == 1 ~ 0,
                              hispanic == 2 ~ 1,
                              hispanic == 3 ~ 1,
                              hispanic == 4 ~ 1,
                              hispanic == 5 ~ 1,
                              hispanic == 6 ~ 1,
                              hispanic == 7 ~ 1,
                              hispanic == 8 ~ 1,
                              hispanic == 9 ~ 1,
                              hispanic == 10 ~ 1,
                              hispanic == 11 ~ 1,
                              hispanic == 12 ~ 0,
                              hispanic == 13 ~ 1,
                              hispanic == 14 ~ 1,
                              hispanic == 15 ~ 0,
                              hispanic == 16 ~ 1),
         parent = factor(parent, levels=c("No", "Yes")),
         region = case_when(region == 1 ~ "Northeast",
                            region == 2 ~ "Midwest",
                            region == 3 ~ "South",
                            region == 4 ~ "West"),
  ) %>%
  select(project_assignment, education_rank, employment_rank, defense_rank, healthcare_rank, 
         public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank, 
         education_therm, employment_therm, defense_therm, healthcare_therm, public_safety_therm, 
         public_lands_therm, evironment_therm, economy_therm, transportation_therm, 
         education_allocate, employment_allocate, defense_allocate, healthcare_allocate, 
         public_safety_allocate, public_lands_allocate, evironment_allocate, economy_allocate, 
         transportation_allocate, project_rank, project_rank_rev, project_therm, project_allocate, 
         project_rank_cat, feeling_change, effective_change, represent_change, responsible_change, partyr, partytwo, 
         income, resp_gender, region, age, education, 
         ideo, black, hisplat, asam, natam, white, multiracial, rother, race, hispanic, parent)

# Appendix A ----
# Figure A1
ds %>% 
  select(partyr,
         resp_gender,
         age,
         race, 
         hispanic,
         education, 
         income,
         parent) %>% 
  tbl_summary(missing = "no",
              label = c(partyr ~ "Party",
                        resp_gender ~ "Gender", 
                        age ~ "Age",
                        race ~ "Race",
                        hispanic ~ "Hispanic",
                        education ~ "Education",
                        income ~ "Income",
                        parent ~ "Parent")) %>% 
  italicize_levels() %>%
  modify_header(label ~ "**Variable**") -> figure_a1

# Figure A2
ds %>% 
  select(partyr,
         resp_gender,
         age,
         race, 
         hispanic,
         education, 
         income,
         parent,
         project_rank_rev
  ) %>% 
  tbl_summary(by=project_rank_rev, 
              missing = "no", 
              label = c(partyr ~ "Party",
                        resp_gender ~ "Gender", 
                        age ~ "Age",
                        race ~ "Race",
                        hispanic ~ "Hispanic",
                        education ~ "Education",
                        income ~ "Income",
                        parent ~ "Parent")) %>% 
  add_p()%>%
  italicize_levels() %>%
  modify_header(label ~ "**Variable**") -> figure_a2


# Appendix C ----

# Figure C1 
ds <- ds %>%
  mutate(across(ends_with("_rank"), revcode))

ds %>% 
  select(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank, partyr) %>% 
  pivot_longer(
    cols = c(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank),
    cols_vary = "fastest",
    names_to = "type") %>% 
  drop_na(type, value, partyr) %>%
  group_by(type, partyr) %>% 
  summarise(nrow = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(nrow),
            ci = 1.96*se)%>% 
  mutate(type = factor(type, level=c('public_lands_rank','defense_rank','evironment_rank','transportation_rank','economy_rank','public_safety_rank','employment_rank','education_rank','healthcare_rank'))) %>%
  ggplot(., aes(x=type, y = mean, shape = partyr, color = partyr
  )) +
  geom_pointrange(aes(ymin = mean-ci, ymax = mean+ci), position = position_dodge(width = .5), size = 0.25, linewidth=0.5) +
  labs(shape = "",
       y = "Mean Ranking Score (1-9)") +  
  scale_x_discrete(labels=c("education_rank" = "Education", "employment_rank" = "Employement", "defense_rank" = "Defense", "healthcare_rank" = "Healthcare", "public_safety_rank" = "Public Safety", "public_lands_rank" = "Public Lands", "evironment_rank" = "Environment", "economy_rank" = "Local Economy", "transportation_rank" = "Transportation")) +
  scale_shape_manual(values=c(15, 16, 17), labels = c("Dem","Ind","Rep"), name = "Resp. Party")+
  scale_color_manual(values=c("mediumblue","green4","red3"), labels = c("Dem","Ind","Rep"), name = "Resp. Party")+
  geom_vline(xintercept=c(0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5),color="lightgrey", linetype = "dashed")+
  coord_flip()+
  guides(color = guide_legend(reverse = TRUE), shape = guide_legend(reverse = TRUE))+
  mytheme3() +
  theme(legend.position = c(0.905, 0.135)) -> figure_c1

# Figure C2
ds %>%
  select(education_therm, employment_therm, defense_therm, healthcare_therm, public_safety_therm, public_lands_therm, evironment_therm, economy_therm, transportation_therm, partyr) %>% 
  pivot_longer(
    cols = c(education_therm, employment_therm, defense_therm, healthcare_therm, public_safety_therm, public_lands_therm, evironment_therm, economy_therm, transportation_therm),
    cols_vary = "fastest",
    names_to = "type"
  ) %>% 
  drop_na(type, value, partyr) %>%
  group_by(type, partyr) %>% 
  summarise(nrow = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(nrow),
            ci = 1.96*se,
            .groups = "drop") %>% 
  mutate(type = factor(type, levels = c('public_lands_therm','defense_therm','evironment_therm','transportation_therm','economy_therm','public_safety_therm','employment_therm','education_therm','healthcare_therm'))) %>%
  ggplot(aes(x = type, y = mean, shape = partyr, color = partyr)) +
  geom_pointrange(aes(ymin = mean - ci, ymax = mean + ci), 
                  position = position_dodge(width = .5), size = 0.25, linewidth = 0.5) +
  labs(shape = "",
       y = "Mean Spending Thermometer Score (0–100)") +  
  scale_x_discrete(labels = c(
    "education_therm" = "Education",
    "employment_therm" = "Employement",
    "defense_therm" = "Defense",
    "healthcare_therm" = "Healthcare",
    "public_safety_therm" = "Public Safety",
    "public_lands_therm" = "Public Lands",
    "evironment_therm" = "Environment",
    "economy_therm" = "Local Economy",
    "transportation_therm" = "Transportation"
  )) +
  scale_shape_manual(values = c(15, 16, 17), labels = c("Dem", "Ind", "Rep"), name = "Resp. Party") +
  scale_color_manual(values = c("mediumblue", "green4", "red3"), labels = c("Dem", "Ind", "Rep"), name = "Resp. Party") +
  geom_vline(xintercept = c(0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5), color = "lightgrey", linetype = "dashed") +
  coord_flip() +
  guides(color = guide_legend(reverse = TRUE), shape = guide_legend(reverse = TRUE)) +
  mytheme3() +
  theme(legend.position = c(0.905, 0.135)) -> figure_c2

# Tables C1-C12

# C1
ds %>% 
  select(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank) %>% 
  pivot_longer(
    cols = c(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank),
    cols_vary = "fastest",
    names_to = "type") %>% 
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(nrow = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(nrow),
            ci = 1.96*se,
            ci_low = mean-ci,
            ci_high = mean+ci
  ) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption="Mean and 95% CI for Spending Category Ranking",
      #format="latex",
      col.names = c("Type","Mean","Lower %95 CI","Upper %95 CI"),
      align="r") %>%
  kable_minimal(full_width = F,  html_font = "Seriff")

# C2
ds %>% 
  filter(partyr == "dem") %>% 
  select(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank) %>% 
  pivot_longer(
    cols = c(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank),
    cols_vary = "fastest",
    names_to = "type") %>% 
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(nrow = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(nrow),
            ci = 1.96*se,
            ci_low = mean-ci,
            ci_high = mean+ci
  ) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption="Democrats -- Mean and 95% CI for Spending Category Ranking",
      #format="latex",
      col.names = c("Type","Mean","Lower %95 CI","Upper %95 CI"),
      align="r") %>%
  kable_minimal(full_width = F,  html_font = "Seriff")

# C3
ds %>% 
  filter(partyr == "rep") %>% 
  select(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank) %>% 
  pivot_longer(
    cols = c(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank, public_lands_rank, evironment_rank, economy_rank, transportation_rank),
    cols_vary = "fastest",
    names_to = "type") %>% 
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(nrow = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(nrow),
            ci = 1.96*se,
            ci_low = mean-ci,
            ci_high = mean+ci
  ) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption="Republicans -- Mean and 95% CI for Spending Category Ranking",
      #format="latex",
      col.names = c("Type","Mean","Lower %95 CI","Upper %95 CI"),
      align="r") %>%
  kable_minimal(full_width = F,  html_font = "Seriff")

#C4
ds %>% 
  filter(partyr == "ind") %>% 
  select(education_rank, employment_rank, defense_rank, healthcare_rank, public_safety_rank,
         public_lands_rank, evironment_rank, economy_rank, transportation_rank) %>% 
  pivot_longer(
    cols = everything(),
    cols_vary = "fastest",
    names_to = "type") %>% 
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value), 
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Independents – Mean and 95% CI for Spending Category Ranking (Figure 4)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

#C5
ds %>% 
  select(defense_therm, economy_therm, education_therm, employment_therm, 
         evironment_therm, healthcare_therm, public_lands_therm, 
         public_safety_therm, transportation_therm) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Full Sample – Mean and 95% CI for Spending Category Rating (0–100)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

#C6
ds %>% 
  filter(partyr == "dem") %>% 
  select(defense_therm, economy_therm, education_therm, employment_therm, 
         evironment_therm, healthcare_therm, public_lands_therm, 
         public_safety_therm, transportation_therm) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Democrats – Mean and 95% CI for Spending Category Rating (Figure 5)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

# C7
ds %>% 
  filter(partyr == "rep") %>% 
  select(defense_therm, economy_therm, education_therm, employment_therm, 
         evironment_therm, healthcare_therm, public_lands_therm, 
         public_safety_therm, transportation_therm) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Republicans – Mean and 95% CI for Spending Category Rating (Figure 5)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

# C8 
ds %>% 
  filter(partyr == "ind") %>% 
  select(defense_therm, economy_therm, education_therm, employment_therm, 
         evironment_therm, healthcare_therm, public_lands_therm, 
         public_safety_therm, transportation_therm) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Independents – Mean and 95% CI for Spending Category Rating (Figure 5)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

# C9
ds %>% 
  select(defense_allocate, economy_allocate, education_allocate, employment_allocate, 
         evironment_allocate, healthcare_allocate, public_lands_allocate, 
         public_safety_allocate, transportation_allocate) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Full Sample – Mean and 95% CI for Allocation Decisions (0–100)",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

#C10 
ds %>% 
  filter(partyr == "dem") %>% 
  select(defense_allocate, economy_allocate, education_allocate, employment_allocate, 
         evironment_allocate, healthcare_allocate, public_lands_allocate, 
         public_safety_allocate, transportation_allocate) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Democrats – Mean and 95% CI for Allocation Decisions",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

#C11
ds %>% 
  filter(partyr == "rep") %>% 
  select(defense_allocate, economy_allocate, education_allocate, employment_allocate, 
         evironment_allocate, healthcare_allocate, public_lands_allocate, 
         public_safety_allocate, transportation_allocate) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Republicans – Mean and 95% CI for Allocation Decisions",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

#C12
ds %>% 
  filter(partyr == "ind") %>% 
  select(defense_allocate, economy_allocate, education_allocate, employment_allocate, 
         evironment_allocate, healthcare_allocate, public_lands_allocate, 
         public_safety_allocate, transportation_allocate) %>% 
  pivot_longer(cols = everything(), names_to = "type") %>%
  drop_na(type, value) %>%
  group_by(type) %>% 
  summarise(n = length(value),
            mean = mean(value), 
            se = sd(value)/sqrt(n),
            ci = 1.96 * se,
            ci_low = mean - ci,
            ci_high = mean + ci) %>%
  select(type, mean, ci_low, ci_high) %>% 
  kbl(caption = "Independents – Mean and 95% CI for Allocation Decisions",
      col.names = c("Type", "Mean", "Lower %95 CI", "Upper %95 CI"),
      align = "r") %>%
  kable_minimal(full_width = FALSE, html_font = "Serif")

# Appendix E ----

# Table E1
summary(feel_rank_mod_s <- lm(scale(feeling_change) ~  
                                scale(project_rank_rev) 
                              , data = ds))

summary(feel_therm_mod_s <- lm(scale(feeling_change) ~  
                                 scale(project_therm) 
                               , data = ds))

summary(feel_allocate_mod_s <- lm(scale(feeling_change) ~  
                                    scale(project_allocate) 
                                  , data = ds))

models1_s <- list()
models1_s[['Rating']] <- feel_therm_mod_s
models1_s[['Allocation']] <- feel_allocate_mod_s
models1_s[['Ranking']] <- feel_rank_mod_s

coefs <- c("scale(project_therm)" = "Rating",
           "scale(project_allocate)" = "Allocation",
           "scale(project_rank_rev)" = "Ranking",
           "(Intercept)" = "Constant")

modelsummary(models1_s, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E2

summary(effect_rank_mod_s <- lm(scale(effective_change) ~  
                                  scale(project_rank_rev) 
                                , data = ds))

summary(effect_therm_mod_s <- lm(scale(effective_change) ~  
                                   scale(project_therm) 
                                 , data = ds))

summary(effect_allocate_mod_s <- lm(scale(effective_change) ~  
                                      scale(project_allocate) 
                                    , data = ds))

models2_s <- list()
models2_s[['Rating']] <- effect_therm_mod_s
models2_s[['Allocation']] <- effect_allocate_mod_s
models2_s[['Ranking']] <- effect_rank_mod_s

modelsummary(models2_s, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E3
summary(represent_rank_mod_s <- lm(scale(represent_change) ~  
                                     scale(project_rank_rev) 
                                   , data = ds))

summary(represent_therm_mod_s <- lm(scale(represent_change) ~  
                                      scale(project_therm) 
                                    , data = ds))

summary(represent_allocate_mod_s <- lm(scale(represent_change) ~  
                                         scale(project_allocate) 
                                       , data = ds))

models3_s <- list()
models3_s[['Rating']] <- represent_therm_mod_s
models3_s[['Allocation']] <- represent_allocate_mod_s
models3_s[['Ranking']] <- represent_rank_mod_s

modelsummary(models3_s, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E4
summary(responsible_rank_mod_s <- lm(scale(responsible_change) ~  
                                       scale(project_rank_rev) 
                                     , data = ds))

summary(responsible_therm_mod_s <- lm(scale(responsible_change) ~  
                                        scale(project_therm) 
                                      , data = ds))

summary(responsible_allocate_mod_s <- lm(scale(responsible_change) ~  
                                           scale(project_allocate) 
                                         , data = ds))

models4_s <- list()
models4_s[['Rating']] <- responsible_therm_mod_s
models4_s[['Allocation']] <- responsible_allocate_mod_s
models4_s[['Ranking']] <- responsible_rank_mod_s

modelsummary(models4_s, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E5
ds_d <- subset(ds, partytwo == "dem")

summary(feel_rank_mod_sd <- lm(scale(feeling_change) ~  
                                 scale(project_rank_rev) 
                               , data = ds_d))

summary(feel_therm_mod_sd <- lm(scale(feeling_change) ~  
                                  scale(project_therm) 
                                , data = ds_d))

summary(feel_allocate_mod_sd <- lm(scale(feeling_change) ~  
                                     scale(project_allocate) 
                                   , data = ds_d))

models1_sd <- list()
models1_sd[['Rating']] <- feel_therm_mod_sd
models1_sd[['Allocation']] <- feel_allocate_mod_sd
models1_sd[['Ranking']] <- feel_rank_mod_sd

modelsummary(models1_sd, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E6
summary(effect_rank_mod_sd <- lm(scale(effective_change) ~  
                                   scale(project_rank_rev) 
                                 , data = ds_d))

summary(effect_therm_mod_sd <- lm(scale(effective_change) ~  
                                    scale(project_therm) 
                                  , data = ds_d))

summary(effect_allocate_mod_sd <- lm(scale(effective_change) ~  
                                       scale(project_allocate) 
                                     , data = ds_d))

models2_sd <- list()
models2_sd[['Rating']] <- effect_therm_mod_sd
models2_sd[['Allocation']] <- effect_allocate_mod_sd
models2_sd[['Ranking']] <- effect_rank_mod_sd

modelsummary(models2_sd, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E7
summary(represent_rank_mod_sd <- lm(scale(represent_change) ~  
                                      scale(project_rank_rev) 
                                    , data = ds_d))

summary(represent_therm_mod_sd <- lm(scale(represent_change) ~  
                                       scale(project_therm) 
                                     , data = ds_d))

summary(represent_allocate_mod_sd <- lm(scale(represent_change) ~  
                                          scale(project_allocate) 
                                        , data = ds_d))

models3_sd <- list()
models3_sd[['Rating']] <- represent_therm_mod_sd
models3_sd[['Allocation']] <- represent_allocate_mod_sd
models3_sd[['Ranking']] <- represent_rank_mod_sd

modelsummary(models3_sd, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E8
summary(responsible_rank_mod_sd <- lm(scale(responsible_change) ~  
                                        scale(project_rank_rev) 
                                      , data = ds_d))

summary(responsible_therm_mod_sd <- lm(scale(responsible_change) ~  
                                         scale(project_therm) 
                                       , data = ds_d))

summary(responsible_allocate_mod_sd <- lm(scale(responsible_change) ~  
                                            scale(project_allocate) 
                                          , data = ds_d))

models4_sd <- list()
models4_sd[['Rating']] <- responsible_therm_mod_sd
models4_sd[['Allocation']] <- responsible_allocate_mod_sd
models4_sd[['Ranking']] <- responsible_rank_mod_sd

modelsummary(models4_sd, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E9
ds_r <- subset(ds, partytwo == "rep")

summary(feel_rank_mod_sr <- lm(scale(feeling_change) ~  
                                 scale(project_rank_rev) 
                               , data = ds_r))

summary(feel_therm_mod_sr <- lm(scale(feeling_change) ~  
                                  scale(project_therm) 
                                , data = ds_r))

summary(feel_allocate_mod_sr <- lm(scale(feeling_change) ~  
                                     scale(project_allocate) 
                                   , data = ds_r))

models1_sr <- list()
models1_sr[['Rating']] <- feel_therm_mod_sr
models1_sr[['Allocation']] <- feel_allocate_mod_sr
models1_sr[['Ranking']] <- feel_rank_mod_sr

modelsummary(models1_sr, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )
# Table E10
summary(effect_rank_mod_sr <- lm(scale(effective_change) ~  
                                   scale(project_rank_rev) 
                                 , data = ds_r))

summary(effect_therm_mod_sr <- lm(scale(effective_change) ~  
                                    scale(project_therm) 
                                  , data = ds_r))

summary(effect_allocate_mod_sr <- lm(scale(effective_change) ~  
                                       scale(project_allocate) 
                                     , data = ds_r))

models2_sr <- list()
models2_sr[['Rating']] <- effect_therm_mod_sr
models2_sr[['Allocation']] <- effect_allocate_mod_sr
models2_sr[['Ranking']] <- effect_rank_mod_sr

modelsummary(models2_sr, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E11
summary(represent_rank_mod_sr <- lm(scale(represent_change) ~  
                                      scale(project_rank_rev) 
                                    , data = ds_r))

summary(represent_therm_mod_sr <- lm(scale(represent_change) ~  
                                       scale(project_therm) 
                                     , data = ds_r))

summary(represent_allocate_mod_sr <- lm(scale(represent_change) ~  
                                          scale(project_allocate) 
                                        , data = ds_r))

models3_sr <- list()
models3_sr[['Rating']] <- represent_therm_mod_sr
models3_sr[['Allocation']] <- represent_allocate_mod_sr
models3_sr[['Ranking']] <- represent_rank_mod_sr

modelsummary(models3_sr, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E12
summary(responsible_rank_mod_sr <- lm(scale(responsible_change) ~  
                                        scale(project_rank_rev) 
                                      , data = ds_r))

summary(responsible_therm_mod_sr <- lm(scale(responsible_change) ~  
                                         scale(project_therm) 
                                       , data = ds_r))

summary(responsible_allocate_mod_sr <- lm(scale(responsible_change) ~  
                                            scale(project_allocate) 
                                          , data = ds_r))

models4_sr <- list()
models4_sr[['Rating']] <- responsible_therm_mod_sr
models4_sr[['Allocation']] <- responsible_allocate_mod_sr
models4_sr[['Ranking']] <- responsible_rank_mod_sr

modelsummary(models4_sr, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E13
ds_i <- subset(ds, partyr == "ind")

summary(feel_rank_mod_si <- lm(scale(feeling_change) ~  
                                 scale(project_rank_rev) 
                               , data = ds_i))

summary(feel_therm_mod_si <- lm(scale(feeling_change) ~  
                                  scale(project_therm) 
                                , data = ds_i))

summary(feel_allocate_mod_si <- lm(scale(feeling_change) ~  
                                     scale(project_allocate) 
                                   , data = ds_i))

models1_si <- list()
models1_si[['Rating']] <- feel_therm_mod_si
models1_si[['Allocation']] <- feel_allocate_mod_si
models1_si[['Ranking']] <- feel_rank_mod_si

modelsummary(models1_si, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E14
summary(effect_rank_mod_si <- lm(scale(effective_change) ~  
                                   scale(project_rank_rev) 
                                 , data = ds_i))

summary(effect_therm_mod_si <- lm(scale(effective_change) ~  
                                    scale(project_therm) 
                                  , data = ds_i))

summary(effect_allocate_mod_si <- lm(scale(effective_change) ~  
                                       scale(project_allocate) 
                                     , data = ds_i))

models2_si <- list()
models2_si[['Rating']] <- effect_therm_mod_si
models2_si[['Allocation']] <- effect_allocate_mod_si
models2_si[['Ranking']] <- effect_rank_mod_si

modelsummary(models2_si, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E15
summary(represent_rank_mod_si <- lm(scale(represent_change) ~  
                                      scale(project_rank_rev) 
                                    , data = ds_i))

summary(represent_therm_mod_si <- lm(scale(represent_change) ~  
                                       scale(project_therm) 
                                     , data = ds_i))

summary(represent_allocate_mod_si <- lm(scale(represent_change) ~  
                                          scale(project_allocate) 
                                        , data = ds_i))

models3_si <- list()
models3_si[['Rating']] <- represent_therm_mod_si
models3_si[['Allocation']] <- represent_allocate_mod_si
models3_si[['Ranking']] <- represent_rank_mod_si

modelsummary(models3_si, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E16
summary(responsible_rank_mod_si <- lm(scale(responsible_change) ~  
                                        scale(project_rank_rev) 
                                      , data = ds_i))

summary(responsible_therm_mod_si <- lm(scale(responsible_change) ~  
                                         scale(project_therm) 
                                       , data = ds_i))

summary(responsible_allocate_mod_si <- lm(scale(responsible_change) ~  
                                            scale(project_allocate) 
                                          , data = ds_i))

models4_si <- list()
models4_si[['Rating']] <- responsible_therm_mod_si
models4_si[['Allocation']] <- responsible_allocate_mod_si
models4_si[['Ranking']] <- responsible_rank_mod_si

modelsummary(models4_si, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E17
summary(feel_rank_mod_int <- lm(feeling_change ~  
                                  project_rank_rev * partytwo
                                , data = ds))

summary(feel_therm_mod_int <- lm(feeling_change ~  
                                   project_therm * partytwo
                                 , data = ds))

summary(feel_allocate_mod_int <- lm(feeling_change ~  
                                      project_allocate * partytwo
                                    , data = ds))

models1_int <- list()
models1_int[['Rating']] <- feel_therm_mod_int
models1_int[['Allocation']] <- feel_allocate_mod_int
models1_int[['Ranking']] <- feel_rank_mod_int

int.coefs <- c("project_therm" = "Project Priority: Rating",
               "project_allocate" = "Project Priority: Allocation",
               "project_rank_rev" = "Project Priority: Ranking",
               "partytworep" = "Republican Resp.",
               "project_rank_rev:partytworep" = "Project Priority X Republican Resp.",
               "project_therm:partytworep" = "Project Priority X Republican Resp.",
               "project_allocate:partytworep" = "Project Priority X Republican Resp.",
               "(Intercept)" = "Constant")

modelsummary(models1_int, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = int.coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )

# Table E18
summary(effect_rank_mod_int <- lm(effective_change ~  
                                    project_rank_rev * partytwo
                                  , data = ds))

summary(effect_therm_mod_int <- lm(effective_change ~  
                                     project_therm * partytwo 
                                   , data = ds))

summary(effect_allocate_mod_int <- lm(effective_change ~  
                                        project_allocate * partytwo 
                                      , data = ds))

models2_int <- list()
models2_int[['Rating']] <- effect_therm_mod_int
models2_int[['Allocation']] <- effect_allocate_mod_int
models2_int[['Ranking']] <- effect_rank_mod_int

modelsummary(models2_int, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = int.coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )
#Table E19
summary(represent_rank_mod_int <- lm(represent_change ~  
                                       project_rank_rev * partytwo 
                                     , data = ds))

summary(represent_therm_mod_int <- lm(represent_change ~  
                                        project_therm * partytwo 
                                      , data = ds))

summary(represent_allocate_mod_int <- lm(represent_change ~  
                                           project_allocate * partytwo 
                                         , data = ds))

models3_int <- list()
models3_int[['Rating']] <- represent_therm_mod_int
models3_int[['Allocation']] <- represent_allocate_mod_int
models3_int[['Ranking']] <- represent_rank_mod_int

modelsummary(models3_int, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = int.coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )
#Table E20
summary(responsible_rank_mod_int <- lm(responsible_change ~  
                                         project_rank_rev * partytwo
                                       , data = ds))

summary(responsible_therm_mod_int <- lm(responsible_change ~  
                                          project_therm * partytwo
                                        , data = ds))

summary(responsible_allocate_mod_int <- lm(responsible_change ~  
                                             project_allocate * partytwo
                                           , data = ds))

models4_int <- list()
models4_int[['Rating']] <- responsible_therm_mod_int
models4_int[['Allocation']] <- responsible_allocate_mod_int
models4_int[['Ranking']] <- responsible_rank_mod_int

modelsummary(models4_int, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = int.coefs,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE', col.names = NULL,
             #output = "latex"
             )
# Table E21
summary(feel_rank_cat_mod <- lm(feeling_change ~  
                                  project_rank_cat 
                                , data = ds))
summary(effect_rank_cat_mod <- lm(effective_change ~  
                                    project_rank_cat 
                                  , data = ds))
summary(represent_rank_cat_mod <- lm(represent_change ~  
                                       project_rank_cat
                                     , data = ds))
summary(responsible_rank_cat_mod <- lm(responsible_change ~  
                                         project_rank_cat 
                                       , data = ds))
models.cat <- list()
models.cat[['Thermometer']] <- feel_rank_cat_mod
models.cat[['Effectiveness']] <- effect_rank_cat_mod
models.cat[['Representation']] <- represent_rank_cat_mod
models.cat[['Responsible']] <- responsible_rank_cat_mod

coefs_cat <- c("project_rank_catmid" = "Medium Priority",
               "project_rank_cathigh" = "High Priority",
               "partytworep" = "Republican Respondent",
               "project_rank_catmid:partytworep" = "Medium Priority X Republican",
               "project_rank_cathigh:partytworep" = "High Priority X Republican",
               "(Intercept)" = "Constant")

modelsummary(models.cat, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs_cat,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE',
             notes = "Reference category: Low Priority",
             #output = "latex"
             )

# Table E22
summary(feel_rank_cat_mod_int <- lm(feeling_change ~  
                                      project_rank_cat * partytwo
                                    , data = ds))
summary(effect_rank_cat_mod_int <- lm(effective_change ~  
                                        project_rank_cat * partytwo 
                                      , data = ds))
summary(represent_rank_cat_mod_int <- lm(represent_change ~  
                                           project_rank_cat * partytwo 
                                         , data = ds))
summary(responsible_rank_cat_mod_int <- lm(responsible_change ~  
                                             project_rank_cat * partytwo
                                           , data = ds))

models.cat.i <- list()
models.cat.i[['Thermometer']] <- feel_rank_cat_mod_int
models.cat.i[['Effectiveness']] <- effect_rank_cat_mod_int
models.cat.i[['Representation']] <- represent_rank_cat_mod_int
models.cat.i[['Responsible']] <- responsible_rank_cat_mod_int

modelsummary(models.cat.i, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs_cat,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE',
             notes = "Reference category: Low Priority",
             #output = "latex"
             )
# Table E23
summary(feel_rank_mod_edu_int <- lm(scale(feeling_change) ~  
                                      scale(project_rank_rev) * education 
                                    , data = ds))

summary(feel_therm_mod_edu_int <- lm(scale(feeling_change) ~  
                                       scale(project_therm) * education 
                                     , data = ds))

summary(feel_allocate_mod_edu_int <- lm(scale(feeling_change) ~  
                                          scale(project_allocate) * education
                                        , data = ds))

models.feel.edu <- list()
models.feel.edu[['Rating']] <- feel_therm_mod_edu_int
models.feel.edu[['Allocation']] <- feel_allocate_mod_edu_int
models.feel.edu[['Ranking']] <- feel_rank_mod_edu_int

summary(feel_rank_mod_edu_int)

coefs.edu <- c("scale(project_therm)" = "Project Rating",
               "scale(project_allocate)" = "Project Allocation",
               "scale(project_rank_rev)" = "Project Ranking",
               "educationLess_than_Bachelors" = "Resp. Edu: Less than Bachelors Degree",
               "scale(project_therm):educationLess_than_Bachelors" = "Project Rating X Less than Bachelors Degree",
               "scale(project_allocate):educationLess_than_Bachelors" = "Project Allocation X Less than Bachelors Degree",
               "scale(project_rank_rev):educationLess_than_Bachelors" = "Project Ranking X Less than Bachelors Degree",
               "(Intercept)" = "Constant")

modelsummary(models.feel.edu, 
             stars = c('*' = .1, '**' = .05, '***' = .01),
             coef_map = coefs.edu,
             fmt = 2,
             title = '',
             gof_omit = 'R2 Adj.|Log.Lik.|F|AIC|BIC|RMSE',
             #output = "latex"
             )

# Figure E1
as.data.frame(modelplot(models1_s, draw = FALSE)) -> dS_mod1_s
as.data.frame(modelplot(models2_s, draw = FALSE)) -> dS_mod2_s
as.data.frame(modelplot(models3_s, draw = FALSE)) -> dS_mod3_s
as.data.frame(modelplot(models4_s, draw = FALSE)) -> dS_mod4_s

dS_mod1_s$dv <- "Feeling"
dS_mod2_s$dv <- "Effective"
dS_mod3_s$dv <- "Represent"
dS_mod4_s$dv <- "Responsible"

ds_mods <- rbind(dS_mod1_s,dS_mod2_s,dS_mod3_s,dS_mod4_s) %>% 
  filter(term %in% c("scale(project_therm)", "scale(project_allocate)", "scale(project_rank_rev)"))

dv.labs <- c("Feeling Therm.", "Effective", "Representation", "Responsible")
names(dv.labs) <- c("Feeling", "Effective", "Represent", "Responsible")

ds_mods$dv <- fct_relevel(ds_mods$dv,"Feeling", "Effective", "Represent", "Responsible")

ggplot(ds_mods, aes(x = model, y = estimate)) + 
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), linewidth=1) + 
  labs(x = "Assigned Project Demand Measure",
       y = "Standardized Coefficient") + 
  scale_y_continuous(n.breaks = 4, limits = c(-0.05, 0.2)) +
  geom_hline(yintercept = 0, color='black', linetype = 'dashed')+
  coord_flip()+
  mytheme4() + facet_grid(~dv, labeller = labeller(dv = dv.labs)) -> figure_e1

# figure E2
as.data.frame(modelplot(models1_sd, draw = FALSE)) -> dS_mod1_sd
as.data.frame(modelplot(models2_sd, draw = FALSE)) -> dS_mod2_sd
as.data.frame(modelplot(models3_sd, draw = FALSE)) -> dS_mod3_sd
as.data.frame(modelplot(models4_sd, draw = FALSE)) -> dS_mod4_sd

dS_mod1_sd$dv <- "Feeling"
dS_mod2_sd$dv <- "Effective"
dS_mod3_sd$dv <- "Represent"
dS_mod4_sd$dv <- "Responsible"

ds_modsd <- rbind(dS_mod1_sd,dS_mod2_sd,dS_mod3_sd,dS_mod4_sd) %>% 
  filter(term %in% c("scale(project_therm)", "scale(project_allocate)", "scale(project_rank_rev)"))

as.data.frame(modelplot(models1_sr, draw = FALSE)) -> dS_mod1_sr
as.data.frame(modelplot(models2_sr, draw = FALSE)) -> dS_mod2_sr
as.data.frame(modelplot(models3_sr, draw = FALSE)) -> dS_mod3_sr
as.data.frame(modelplot(models4_sr, draw = FALSE)) -> dS_mod4_sr

dS_mod1_sr$dv <- "Feeling"
dS_mod2_sr$dv <- "Effective"
dS_mod3_sr$dv <- "Represent"
dS_mod4_sr$dv <- "Responsible"

ds_modsr <- rbind(dS_mod1_sr,dS_mod2_sr,dS_mod3_sr,dS_mod4_sr) %>% 
  filter(term %in% c("scale(project_therm)", "scale(project_allocate)", "scale(project_rank_rev)"))

as.data.frame(modelplot(models1_si, draw = FALSE)) -> dS_mod1_si
as.data.frame(modelplot(models2_si, draw = FALSE)) -> dS_mod2_si
as.data.frame(modelplot(models3_si, draw = FALSE)) -> dS_mod3_si
as.data.frame(modelplot(models4_si, draw = FALSE)) -> dS_mod4_si

dS_mod1_si$dv <- "Feeling"
dS_mod2_si$dv <- "Effective"
dS_mod3_si$dv <- "Represent"
dS_mod4_si$dv <- "Responsible"

ds_modsi <- rbind(dS_mod1_si,dS_mod2_si,dS_mod3_si,dS_mod4_si) %>% 
  filter(term %in% c("scale(project_therm)", "scale(project_allocate)", "scale(project_rank_rev)"))

ds_modsr$r_party <- "Reps"
ds_modsd$r_party <- "Dems"
ds_modsi$r_party <- "Inds"

ds_mods_com <- rbind(ds_modsr,ds_modsd, ds_modsi) 

ggplot(ds_mods_com, aes(x = model, y = estimate, color = r_party, shape = r_party)) + 
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), linewidth=1, position = position_dodge(width = .5)) + 
  labs(x = "Assigned Project Demand Measure",
       y = "Standardized Coefficient") + 
  scale_shape_manual(values=c(15, 16, 17), labels = c("Dem","Ind","Rep"), name = "Resp. Party")+
  scale_y_continuous(n.breaks = 4, limits = c(-0.05, 0.28)) +
  scale_color_manual(values=c("mediumblue","green4","red3"), labels = c("Dem","Ind","Rep"), name = "Resp. Party")+
  geom_hline(yintercept = 0, color='black', linetype = 'dashed')+
  coord_flip()+
  guides(color = guide_legend(reverse = TRUE), shape = guide_legend(reverse = TRUE))+
  mytheme4() + facet_grid(~dv, labeller = labeller(dv = dv.labs)) -> figure_e2

## Appendix F ----

# Table F1
therm.anova = aov(feeling_change ~ project_rank_cat, ds)
TukeyHSD(therm.anova, conf.level=.95) -> anova.therm.mod.results

anova.therm.mod.results.df <- map_df(list(anova.therm.mod.results), .id = "dv", tidy)
anova.therm.results.df <- anova.therm.mod.results.df[c("contrast", "estimate", "adj.p.value")]

Con <- c("Medium Priority-Low Priority","High Priority-Low Priority","High Priority-Medium Priority")

anova.therm.results.df$Con <- Con

pvalue_format <- function(x){
  z <- cut(as.numeric(x), breaks = c(-Inf, 0.01, 0.05, 0.1, Inf), labels = c("***", "**", "*", ""))
  as.character(z)
  }

flextable(anova.therm.results.df,
          col_keys = c("Con", "estimate", "adj.p.value", "signif")) %>% 
  colformat_double(digits = 3) %>% 
  mk_par(j = "signif", value = as_paragraph(pvalue_format(adj.p.value)) ) %>% 
  set_header_labels(dv = "Dependent Variable", 
                    Con = "Contrast", estimate = "Diff. of Means",
                    adj.p.value = "Adjusted Pr(>|t|)", signif = "" ) %>% 
  align(j = "signif", align = "left") %>% 
  padding(padding.right = 0, j = "adj.p.value", part  = "all") %>% 
  bold(j = "signif", bold = TRUE) %>% 
  padding(padding.left = 0, j = "signif", part  = "all") %>% 
  autofit() -> table_f1

# Table F2
effect.anova = aov(effective_change ~ project_rank_cat, ds)
TukeyHSD(effect.anova, conf.level=.95) -> anova.eff.mod.results

anova.eff.mod.results.df <- map_df(list(anova.eff.mod.results), .id = "dv", tidy)
anova.eff.results.df <- anova.eff.mod.results.df[c("contrast", "estimate", "adj.p.value")]

anova.eff.results.df$Con <- Con

flextable(anova.eff.results.df,
          col_keys = c("Con", "estimate", "adj.p.value", "signif")) %>% 
  colformat_double(digits = 3) %>% 
  mk_par(j = "signif", value = as_paragraph(pvalue_format(adj.p.value)) ) %>% 
  set_header_labels(dv = "Dependent Variable", 
                    Con = "Contrast", estimate = "Diff. of Means",
                    adj.p.value = "Adjusted Pr(>|t|)", signif = "" ) %>% 
  align(j = "signif", align = "left") %>% 
  padding(padding.right = 0, j = "adj.p.value", part  = "all") %>% 
  bold(j = "signif", bold = TRUE) %>% 
  padding(padding.left = 0, j = "signif", part  = "all") %>% 
  autofit() -> table_f2

#Table F3
represent.anova = aov(represent_change ~ project_rank_cat, ds)
TukeyHSD(represent.anova, conf.level=.95) -> anova.rep.mod.results

anova.rep.mod.results.df <- map_df(list(anova.rep.mod.results), .id = "dv", tidy)
anova.rep.results.df <- anova.rep.mod.results.df[c("contrast", "estimate", "adj.p.value")]

anova.rep.results.df$Con <- Con


flextable(anova.rep.results.df,
          col_keys = c("Con", "estimate", "adj.p.value", "signif")) %>% 
  colformat_double(digits = 3) %>% 
  mk_par(j = "signif", value = as_paragraph(pvalue_format(adj.p.value)) ) %>% 
  set_header_labels(dv = "Dependent Variable", 
                    Con = "Contrast", estimate = "Diff. of Means",
                    adj.p.value = "Adjusted Pr(>|t|)", signif = "" ) %>% 
  align(j = "signif", align = "left") %>% 
  padding(padding.right = 0, j = "adj.p.value", part  = "all") %>% 
  bold(j = "signif", bold = TRUE) %>% 
  padding(padding.left = 0, j = "signif", part  = "all") %>% 
  autofit() -> table_f3

#Table F4
responsible.anova = aov(responsible_change ~ project_rank_cat, ds)
TukeyHSD(responsible.anova, conf.level=.95) -> anova.resp.mod.results

anova.resp.mod.results.df <- map_df(list(anova.resp.mod.results), .id = "dv", tidy)
anova.resp.results.df <- anova.resp.mod.results.df[c("contrast", "estimate", "adj.p.value")]

anova.resp.results.df$Con <- Con

flextable(anova.resp.results.df,
          col_keys = c("Con", "estimate", "adj.p.value", "signif")) %>% 
  colformat_double(digits = 3) %>% 
  mk_par(j = "signif", value = as_paragraph(pvalue_format(adj.p.value)) ) %>% 
  set_header_labels(dv = "Dependent Variable", 
                    Con = "Contrast", estimate = "Diff. of Means",
                    adj.p.value = "Adjusted Pr(>|t|)", signif = "" ) %>% 
  align(j = "signif", align = "left") %>% 
  padding(padding.right = 0, j = "adj.p.value", part  = "all") %>% 
  bold(j = "signif", bold = TRUE) %>% 
  padding(padding.left = 0, j = "signif", part  = "all") %>% 
  autofit() -> table_f4



